package com.loongxun.xxapp.ui.pass;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.loongxun.xxapp.R;

/**
 * 忘记密码-验证手机号
 * Created by Administrator on 2017/10/24.
 */
public class PassChangePhoneActivity extends Activity implements View.OnClickListener{

    private TextView tv_pass_code;

    private TimeCount time;

    private TextView tv_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone_pass_change);

        findViewById(R.id.iv_back).setOnClickListener(this);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText("验证手机号");

        //验证手机号
        tv_pass_code = (TextView) findViewById(R.id.tv_pass_code);
        tv_pass_code.setOnClickListener(this);
        findViewById(R.id.tv_goto_pass).setOnClickListener(this);

        time = new TimeCount(60000, 1000);
    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_pass_code:
                time.start();// 开始计时
                break;
            case R.id.tv_goto_pass:
                intent = new Intent(this,PassChangeActivity.class);
                startActivityForResult(intent, 1);
                break;
            default:
                break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1) {
            if (data != null){
//                CloseKeyBoard();
                Intent intent = new Intent();
                intent.putExtra("login", true);
                setResult(Activity.RESULT_OK, intent);
                finish();
            }
        }
    }

    class TimeCount extends CountDownTimer {

        public TimeCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {// 计时过程
            tv_pass_code.setClickable(false);//防止重复点击
            tv_pass_code.setText(millisUntilFinished / 1000 + "秒后重新获取");
        }

        @Override
        public void onFinish() {// 计时完毕
            tv_pass_code.setText("点击获取验证码");
            tv_pass_code.setClickable(true);
        }
    }
}
